﻿using Coolzon.Realtime.Contracts;
using Coolzon.Realtime.Contracts.CommandData;
using Coolzon.UI.Common.Event;
using Coolzon.UI.Common.Event.NCL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Coolzon.UI.Common.RealtimeProxies
{
    public class LoginHandler : BaseResponseHandler<RespLoginData>
    {
        protected override void OnHandle(RemoteEventProxy remoteEventProxy, Response response, RespLoginData responseData)
        {
            if (responseData.IsSuccess)
            {
                LoginEnd @event = new LoginEnd(NCLEventState.Finished);
                @event.UserAccount = responseData.UserIdentity;
                @event.UserIdentity = responseData.UserIdentity;
                @event.UserName = responseData.UserName;
                NCLEventBus.PublishAsync(@event);
            }
            else
            {
                LoginEnd @event = new LoginEnd(NCLEventState.Failure);
                @event.Error = new Exception(responseData.Message);
                NCLEventBus.PublishAsync(@event);
            }
        }
    }
}
